
import {handleActions} from 'redux-actions'
import * as TYPES from "../constants/actions"

export default   handleActions({
  [TYPES.REQUEST_BEGIN]: (state, action) => {
    let newFetchingCount = ++state.isFetching;
    return Object.assign({},state,{isFetching:newFetchingCount})
  },

  [TYPES.REQUEST_COMPLETE]: (state, action) => {
    let newFetchingCount = state.isFetching === 0 ? 0 : --state.isFetching ;
    return Object.assign({},state,{isFetching:newFetchingCount,templateID:4})
  },

  [TYPES.ERROR_OCCUR]: (state, action) =>{
    let result = Object.assign({},state,{errorDetail: action.payload})
    return result
  },
  [TYPES.CLEAR_ERRORS]: (state, action) =>{
    let result = Object.assign({},state,{errorDetail: action.payload})
    return result
  }
}, {isFetching: 0, errorDetail:''});
